package free.grnadav.jquerymobilegwt.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

import free.grnadav.jquerymobilegwt.client.page.Page;
import free.grnadav.jquerymobilegwt.client.page.PageBeforeCreateEvent;
import free.grnadav.jquerymobilegwt.client.page.PageBeforeShowEvent;
import free.grnadav.jquerymobilegwt.client.page.PageCreateEvent;
import free.grnadav.jquerymobilegwt.client.page.PageShowEvent;
import free.grnadav.jquerymobilegwt.client.button.*;
import free.grnadav.jquerymobilegwt.client.button.Button.IconPosition;
import free.grnadav.jquerymobilegwt.client.button.HeaderButton.HeaderButtonPosition;
import free.grnadav.jquerymobilegwt.client.hasinterface.HasIcon.Icon;

public class Showcase extends Composite {

	private static ShowcaseUiBinder uiBinder = GWT
			.create(ShowcaseUiBinder.class);

	interface ShowcaseUiBinder extends UiBinder<Widget, Showcase> {
	}

	@UiField
	Page page;
	
	@UiField
	HeaderButton headerButton1;
	@UiField
	HeaderButton headerButton2;
	
//	@UiField
//	PageHeader header;
	
	public Showcase() {
		initWidget(uiBinder.createAndBindUi(this));
		page.setId("some-id");
//		header.setText("some header");
		addHandlers();
		headerButton1.setText("button-right");
		headerButton1.setHeaderButtonPosition(HeaderButtonPosition.RIGHT);
		headerButton1.setIcon(Icon.GRID);
		headerButton1.setIconPosition(IconPosition.LEFT);
		
		headerButton2.setText("button-left");
		headerButton2.setHeaderButtonPosition(HeaderButtonPosition.LEFT);
		headerButton2.setIcon(Icon.BACK);
		headerButton2.setIconPosition(IconPosition.RIGHT);
		headerButton2.setBackButton(true);
	}

	private void addHandlers() {
		page.addPageBeforeCreateEventHandler(new PageBeforeCreateEvent.Handler() {
			@Override
			public void onPageBeforeCreate(PageBeforeCreateEvent event) {
				Window.alert("page before create");
			}
		});
		
		page.addPageCreateEventHandler(new PageCreateEvent.Handler() {
			
			@Override
			public void onPageCreate(PageCreateEvent event) {
				Window.alert("page create");
			}
		});
		
		page.addPageBeforeShowEventHandler(new PageBeforeShowEvent.Handler() {
			@Override
			public void onPageBeforeShow(PageBeforeShowEvent event) {
				Window.alert("page before show");
			}
		});
		
		page.addPageShowEventHandler(new PageShowEvent.Handler() {
			
			@Override
			public void onPageShow(PageShowEvent event) {
				Window.alert("page show");
			}
		});
		
	}

	public void init() {
		page.page();
		page.changePageToMe();
	}


}
